package com.asjy.service.impl;

import com.asjy.dao.ProductDao;
import com.asjy.po.CategoryExt;
import com.asjy.po.CategorySecond;
import com.asjy.po.Product;
import com.asjy.po.ProductPageBean;
import com.asjy.service.ProductService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther: lilinlin
 * @Date: 2021/4/9
 * @Description: com.asjy.service.impl
 * @version: 1.0
 */
@Service
public class ProductServiceImpl implements ProductService {
    @Resource
    private ProductDao productDao;
    @Override
    public Map<Integer, List<Product>> getProduct(List<CategoryExt> indexNav) {
        Map<Integer,List<Product>> productMap = new HashMap<>();
       //1.遍历indexNav
        for (CategoryExt categoryExt : indexNav) {
              //2.遍历以及类目下的二级类目
            for (CategorySecond categorySecond : categoryExt.getCategorySecondList()) {
              //3.根据二级类目id，查询商品
                List<Product> productList = productDao.getProductByCsId(categorySecond.getCsId());
                productMap.put(categorySecond.getCsId(),productList);
            }
        }
       return productMap;
    }

    @Override
    //cId ,csId,pageNow
    public ProductPageBean getProductByPageBean(ProductPageBean productPageBean) {
        //获取rowCount的值；
        Integer rowCount = productDao.getRowCountByPageBean(productPageBean);
        //cId ,csId,pageNow,rowCount,pageCount
        productPageBean.setRowCount(rowCount);
        List<Product> products = productDao.getProductByPageBean(productPageBean);
        //cId ,csId,pageNow,rowCount,pageCount,List<product>
        productPageBean.setList(products);
        return productPageBean;
    }

    @Override
    public List<Product> getIsHotProduct(ProductPageBean productPageBean) {
        return productDao.getIsHotProduct(productPageBean);
    }

    @Override
    public Product getProductById(Integer pId) {
        return productDao.getProductById(pId);
    }
}